package com.sky.zero.exception;

import com.sky.zero.enums.SysEnum;

public class BIZException extends RuntimeException {

    public static final String SPLIT = "@@@";

    private static final String ERRORCODE = "500";

    private String bizCode;

    private String bizMsg;

    public BIZException(String message) {
        super(message.contains(SPLIT) ? message : ERRORCODE + SPLIT + message);
        if (message.contains(SPLIT)) {
            this.bizCode = message.split(SPLIT)[0];
            this.bizMsg = message.split(SPLIT)[1];
        } else {
            this.bizCode = ERRORCODE;
            this.bizMsg = message;
        }
    }

    /**
     * code 必须为 int类型
     **/
    public BIZException(String code, String message) {
        super(code + SPLIT + message);
        this.bizCode = code;
        this.bizMsg = message;
    }

    /**
     * code 必须为 int类型
     **/
    public BIZException(Integer code, String message) {
        super(code + SPLIT + message);
        this.bizCode = code.toString();
        this.bizMsg = message;
    }

    public BIZException(SysEnum sysEnum) {
        super(sysEnum.getCode() + SPLIT + sysEnum.getMsg());
        this.bizCode = sysEnum.getCode().toString();
        this.bizMsg = sysEnum.getMsg();
    }

    public BIZException() {
        super(SysEnum.ERROR500.getCode() + SPLIT + SysEnum.ERROR500.getMsg());
        this.bizCode = SysEnum.ERROR500.getCode().toString();
        this.bizMsg = SysEnum.ERROR500.getMsg();
    }

    public BIZException(Exception e) {
        super(SysEnum.ERROR500.getCode() + SPLIT + e.getMessage());
        this.bizCode = SysEnum.ERROR500.getCode().toString();
        this.bizMsg = e.getMessage();
    }

    public String getBizCode() {
        return bizCode;
    }

    public String getBizMsg() {
        return bizMsg;
    }

}
